package com.ruoyi.vote.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.vote.admin.domain.VoteExamine;
import com.ruoyi.vote.admin.mapper.VoteExamineMapper;
import com.ruoyi.vote.admin.service.IVoteExamineService;
import com.ruoyi.vote.common.constants.ModelTypeConstants;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 立勤
 * @date 2023/07/20 19:24:36
 */
@RequiredArgsConstructor
@Service
@Slf4j
public class VoteExamineServiceImpl implements IVoteExamineService {

    private final VoteExamineMapper examineMapper;

    /**
     * 查询模块审核记录
     *
     * @param id    任务ID
     * @return
     */
    @Override
    public VoteExamine getExamine(Long id) {
        return examineMapper.selectById(id);
    }

    /**
     * 查询模块审核记录
     *
     * @param model   模块
     * @param modelId 模块对应ID
     * @return
     */
    @Override
    public List<VoteExamine> getExamineList(String modelType, Long modelId) {
        return examineMapper.selectList(new LambdaQueryWrapper<VoteExamine>()
            .eq(VoteExamine::getModel,modelType)
            .eq(VoteExamine::getModelId,modelId));
    }

    /**
     * 查询模块所有记录
     *
     * @param modelType 模块
     * @return
     */
    @Override
    public List<VoteExamine> getExamineList(String modelType) {
        return examineMapper.selectList(new LambdaQueryWrapper<VoteExamine>()
            .eq(VoteExamine::getModel,modelType));
    }

    /**
     * 添加审核记录
     *
     * @param bo
     * @return
     */
    @Override
    public Boolean insert(VoteExamine bo,  String modelType) {
        if (StringUtils.isEmpty(modelType)){
            return false;
        }
        bo.setModel(modelType);
        return examineMapper.insert(bo) > 0;
    }
}
